#!/usr/bin/env perl
use warnings;
use strict;

use lib 'lib';

use Test::More tests => 4;
use_ok( 'Guile::Space' );

my @tests = (
    {   title   => 'scopeless scheme execution',
        code    => '(+ 1 2 3)',
        result  => 6,
    },
    {   title   => 'scoped integer values',
        code    => '(+ foo bar baz)',
        scope   => { foo => 1, bar => 2, baz => 3 },
        result  => 6,
    },
    {   title   => 'exception in guile-space caught',
        code    => '(+ 12 "bar")',
        catch   => qr/wrong-type-arg/,
    },
);

my $space = Guile::Space->new;

for my $t (@tests) {
    local $@;
    eval { $space->run( code => $t->{code}, scope => $t->{scope} ) }
        if $t->{catch};
    if ( my $test = $t->{catch} ) {
        like( $@, $test, $t->{title} );
        next;
    }

    is( $space->run( code => $t->{code}, scope => $t->{scope} ),
        $t->{result},
        $t->{title},
    );
}



